/*
 * UsageFU.h
 *
 *  Created on: 2009-8-27
 *      Author: ws
 */

#ifndef USAGE_FU_H_
#define USAGE_FU_H_

/*
 * Describe the usage of operation/simd_operation ,
 * include: resource , them relative-time of using resource
 */
#include<vector>
#include<utility>

#include"common.hpp"
class Instruction;
enum _Function_Type
	{
	  FT_ALU = 0,
	  FT_MUL,
	  FT_Shifter,
	  FT_ASPU,
	  FT_ALU_agu,
	  /*
	   * bus is the private resource , because we only need be caution with How many
	   * bus be used with the cluster-from
	   */
	  FT_BUS_X,
	  FT_BUS_Y,
	  FT_BUS_Z,
	  FT_BUS_T,
	  /*
	   * all above is the private resource of the cluster; in another words,
	   *  the Get_Resource_Num (..) means the number resource in one cluster
	   *
	   *  flowing  is the public  resource  in the processor
	   */
	  FT_IMM ,
	  FT_LOAD,
	  FT_STORE,
	  FT_end
	} ;

/*
 * function unit usage class
 */
class UsageFU {
	friend UsageFU Get_Operation_Usage(Instruction * n);
	struct _tupe{
		enum _Function_Type first;
		enum Core second;
		int  third;
		_tupe(enum _Function_Type fu, enum Core core, int time): first(fu), second(core), third(time)
		{

		}
	};
	/*
	 * usage_record[i].first is the resource identify used
	 * usage_record[i].second is the cluster identify used
	 * usage_record[i].third is the  time to use resource
	 * the solution consider the future variation, may be, at one time , have many resource to used .
	 * this make the useage_recorde[time] is poor expressive
	 */
	std::vector <_tupe> usage_record;
	//for private resource the registe  function  will call by Get_Operation_Usage(...);
	void registe(enum _Function_Type , int time, Instruction *n );
public:
	typedef std::vector<_tupe>::const_iterator const_iterator;
	const_iterator begin()const
	{
		return usage_record.begin();
	}
	const_iterator end()const
	{
		return usage_record.end();
	}
	int get_max_offset()
	{
		int max = 0;
		for(int i = 0; i < usage_record.size(); i++	)
		{
			max = (usage_record[i].third > max) ? usage_record[i].third : max;
		}
	}
	UsageFU();
	virtual ~UsageFU();
	//for public resource will call this function in Get_Operation_Usage(NOde * n);
	void push_usage(enum _Function_Type ft, enum Core c, int time)
	{
		usage_record.push_back(_tupe(ft, c, time));
	}
};

UsageFU Get_Operation_Usage(Instruction *n);


#endif /* USAGE_FU_H_ */
